#include "GCOptionsWindow.h"
#include "ui_GCOptionsWindow.h"

GCOptionsWindow::GCOptionsWindow(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::GCOptionsWindow)
{
    ui->setupUi(this);
    connect(this, SIGNAL(accepted()), this, SLOT(saveConfig()));
    connect(ui->makeBrowse, SIGNAL(clicked()), this, SLOT(browseForMake()));
    connect(ui->gppBrowse, SIGNAL(clicked()), this, SLOT(browseForGpp()));
    connect(ui->delBrowse, SIGNAL(clicked()), this, SLOT(browseForDel()));
    connect(ui->binBrowse, SIGNAL(clicked()), this, SLOT(browseForBin()));

    options = new QSettings("game-gen", "game-gen", this);

    options->beginGroup("compile");
    ui->makePath->setText(options->value("make", "mingw32-make").toString());
    ui->gppPath->setText(options->value("g++", "g++").toString());
    ui->gppParams->setText(options->value("g++flags").toString());
    ui->ldParams->setText(options->value("ldflags").toString());
    ui->delPath->setText(options->value("del", "del").toString());
    ui->binPath->setText(options->value("bin").toString());
    options->endGroup();
}

GCOptionsWindow::~GCOptionsWindow()
{
    delete ui;
}

void GCOptionsWindow::saveConfig()
{
    options->beginGroup("infos");
    options->setValue("firstLaunch", false);
    options->endGroup();

    options->beginGroup("compile");
    options->setValue("make", ui->makePath->text());
    options->setValue("g++", ui->gppPath->text());
    options->setValue("g++flags", ui->gppParams->text());
    options->setValue("ldflags", ui->ldParams->text());
    options->setValue("del", ui->delPath->text());
    options->setValue("bin", ui->binPath->text());
    options->endGroup();
}

void GCOptionsWindow::browseForMake()
{
    ui->makePath->setText(QFileDialog::getOpenFileName(this, tr("Recherche de mingw32-make")));
}

void GCOptionsWindow::browseForGpp()
{
    ui->gppPath->setText(QFileDialog::getOpenFileName(this, tr("Recherche de g++")));
}

void GCOptionsWindow::browseForDel()
{
    ui->delPath->setText(QFileDialog::getOpenFileName(this, tr("Recherche de del")));
}

void GCOptionsWindow::browseForBin()
{
    ui->binPath->setText(QFileDialog::getExistingDirectory(this, tr("Recherche du dossier bin de la mingw")));
}
